package poker;

import java.util.ArrayList;

public abstract class player implements Runnable {
	private String nazwa;
	private card[] karty;
	private deck talia;
	private boolean zamiana = false;
	boolean ready = true;
	boolean bot;
	public boolean fold;
	public boolean call;
	public boolean allIN;
	public boolean canBid;
	private int money;
	public int bid;
	protected bidding b;
	
	player(final deck talia, final bidding b) {
		this.b=b;
		this.talia = talia;
	}

	public final String getName() {
		return nazwa;
	}

	protected final void setName(final String name) {
		this.nazwa = name;
	}

	public final String showCards() {
		return karty[0].jakaKarta() + "." + karty[1].jakaKarta() + "."
				+ karty[2].jakaKarta() + "." + karty[3].jakaKarta() + "."
				+ karty[4].jakaKarta();
	}

	protected final void changeCards(final card[] kart) {
		if (zamiana) {
			return;
		}
		for (int j = 0; j < kart.length; j++) {
			for (int i = 0; i < 5; i++) {

				if (kart[j].jakaKarta()
						.contentEquals(this.karty[i].jakaKarta())) {

					try {
						this.karty[i] = talia.takeCard();
						break;
					} catch (deckException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}

			}
		}
		zamiana = true;

	}

	public abstract void msg(String msg);
	public abstract void exit();
	public final void setCards(final card[] karty) {
		this.karty = karty;
		String s = "AKQJ198765432";
		card temp;
		for (int i = 0; i < 5; i++) {
			for (int j = i + 1; j < 5; j++) {
				if (s.indexOf(this.karty[i].figura.charAt(0)) < s
						.indexOf(this.karty[j].figura.charAt(0))) {
					temp = this.karty[i];
					this.karty[i] = this.karty[j];
					this.karty[j] = temp;
				}

			}
		}
		msg("cards." + this.showCards());
	}

	public final card[] getCards() {
		return karty;
	}

	public final void ok() {
		zamiana = false;
		ready = false;
		msg("change");
	}

	public final void setTalia(final deck t) {
		this.talia = t;
	}
	
	public final boolean buyIn(final int x){
		money-=x;
		if(money<0){
			msg("no money");
			return false;
		}
		else{
			msg("money."+money);
			return true;
			}
		}
	public final void setMoney(final int x){
		money+=x;
		msg("money."+money);
	}
	public final int getMoney(){
		return money;
	}
	

}
